package cn.hqc.basic.config;


import cn.hqc.basic.utils.AjaxResult;
import cn.hqc.basic.utils.BussinessException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * controller的增强
 *  全局异常捕获的类
 */
@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler
    public AjaxResult exceptionHandler(Exception e) {

        if (e instanceof BussinessException){
            BussinessException bu = (BussinessException) e;
            return AjaxResult.fail(bu);
        }

        System.out.println("全局异常捕获>>>:" + e);
        e.printStackTrace();
//        return "全局异常捕获,错误原因>>>"+e.getMessage();
        return AjaxResult.fail();
    }
}
